<div id="giohang">
    <div id="nd_gh">
        <h2 class="title">Корзина
            <img onclick="closeDialog();" src="<?php echo base_url('images/x.png') ?>">
        </h2>
		<?php if(isset($cart) && $cart) {?>
        <div class="list_gh">
            <table id="tb1"  cellpadding=0 cellspacing=0>
                <tr style="background: #efece4; height: 30px;" >
                    <td style="width: 55%;padding-left: 8px;">Продукт / Товары</td>
                    <td>Цена</td>
                    <td style="width: 113px;">Количество</td>
                    <td>Сумма</td>
                    <td>Удалить</td>
                </tr>
                <?php
                if(isset($cart)) {
                    foreach($cart as $item) {
					$product = $this->db->where('id', $item['id'])->get('sanpham')->row_array();

                ?>
                <tr >
                    <td>
                        <img src="<?php echo base_url('assets/uploads/images') .'/'. $item['img']; ?>">
                        <span class="ten">Артикул: <?php echo $product['masp']?>
                        </span>
                        <span>
                        Размер: <strong style="color: #F5720B;"><?php echo $product['star-size']?>-<?php echo $product['end-size']?></strong>
                        </span>
                        <span>
                         Пар в коробе: <strong style="color: #F5720B;"><?php echo $product['soluong']?></strong>
                        </span>
                    </td>
                    <td><p class="gia"><?php echo $item['price'] ?> p.</p></td>
                    <td><input type="text" value="<?php echo $item['qty']; ?>"  size="2px;"/>
                    <img class="load" style="cursor: pointer;"   src="<?php echo base_url('images/load.png');?>" rel="<?php echo $item['rowid']; ?>"/></td>
                    <td style="color:#f5720b; font-size: 17px; "><p class="gia"><?php echo $item['subtotal'] ?> p.</p></td>
                    <td><img style="cursor: pointer;" class="bocart" rel="<?php echo $item['rowid']; ?>" src="<?php echo base_url('images/x2.jpg'); ?>"></td>
                </tr>
                    <?php } } ?>
                <tr style="height: 40px;">
                    <td ><span style="margin-left: 13px; margin-bottom: 6px; font-weight: bold; font-size: 17px; color: #f5720b;">Общая Сумма</span></td>
                    <td ></td>
                    <td></td>
                    <td style="font-size: 17px; color: #f5720b; font-weight: bold;" class="total_current"><?php echo $total_all; ?> p.</td>
                    <td></td>
                </tr>

            </table>

        </div>
        <form  method="post" name="aform" id="form_gh">
            <table id="tb2">
                <tr>
                    <td style="text-align: right; vertical-align: top;">Ваше имя <span style="color:red;">*</span>:&nbsp;&nbsp;</td>
                    <td><input name="name"  id="name" type="text"/></td>
                </tr>
                <tr>
                    <td style="text-align: right; vertical-align: top;">E-mail <span style="color:red;">*</span>:&nbsp;&nbsp;</td>
                    <td><input name="email" id="email" type="email"/></td>
                </tr>
                <tr>
                    <td style="text-align: right; vertical-align: top;">Тел. <span style="color:red;">*</span>:&nbsp;&nbsp;</td>
                    <td><input name="phone"  id="phone" type="number" onKeyPress="return numbersonly(this, event)"/></td>
                </tr>
                <tr>
                    <td style="text-align: right; vertical-align: top;">Комментарии:&nbsp;&nbsp;</td>
                    <td><textarea  id="content" name="content" type="text"></textarea></td>
                </tr>
				<tr>
                    <td style="text-align: right; vertical-align: top;">&nbsp;&nbsp;</td>
                    <td>( <span style="color: red;">*</span> ) - Обязательные поля</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input style="cursor: pointer; background: red; color: white; font-weight: bold;" id="sub" type="submit" value="Заказать"></td>
                </tr>
            </table>
        </form>
		<?php } else {?>
		<div style="width: 100%; height: 300px; text-align: center; vertical-align: center">
			Корзина пуста
		</div>
		<?php }?>
    </div>
</div>
    <script type="text/javascript">

        $('.bocart').click(function(){
            $.ajax({
                type: "POST",
                url: "/demo/index.php/cart/remove",
                data: 'rowid='+$(this).attr('rel'),
                success:function(){
                    closeDialog();
                    giohang();
                }
            });
        });

        $(".load").click(function () {
            var rowid = $(this).attr('rel');
            var quantity = $(this).prev().val();
            self = $(this);
            //AJAX
            $.post(
                    '/demo/index.php/cart/ajax_update', // ajax url
                    {rowid:rowid, quantity:quantity}, // tham số truyền đi
                    function (data) {                                 // nhận kết quả
                        if (data.status == true) {
                            self.parent().next().html(data.subtotal + ' p.');
                            $(".total_current").html(data.total_current + ' p.');

                        }
                    },
                    "json"                                          // định dạng dữ liệu mong muốn
            );
        });
        $('#form_gh').submit(function(){
            var name = $('#name').val();
            var email = $('#email').val();
            var phone = $('#phone').val();
            var content = $('#content').val();
            if(name == '') {
                alert('( * ) - Обязательные поля');
                $('#name').focus();
                return false;
            }
            if(email == '') {
                alert('( * ) - Обязательные поля');
                $('#email').focus();
                return false;
            }

            if(phone == ''){
                alert('( * ) - Обязательные поля');
                $('#phone').focus();
                return false;
            }

            if(content == ''){
                alert('( * ) - Обязательные поля');
                $('#content').focus();
                return false;
            }

            $.post(
                    '/demo/index.php/cart/donhang',
                    {name:name, email:email, phone:phone, content:content}
            ).done(function(data) {
				alert("Заказ Выполнено, проверте ваш е-майл");
				closeDialog();
			});
			
			return false;

        });
		
		function numbersonly(myfield, e, dec)
		{
			var key;
			var keychar;

			if (window.event)
				key = window.event.keyCode;
			else if (e)
				key = e.which;
			else
				return true;
			keychar = String.fromCharCode(key);

			if ((key==null) || (key==0) || (key==8) || 
				(key==9) || (key==13) || (key==27) )
				return true;

			else if ((("0123456789").indexOf(keychar) > -1))
				return true;

			else if (dec && (keychar == "."))
			{
				myfield.form.elements[dec].focus();
				return false;
			}
			else
				return false;
		}
    </script>